package com.stadium.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.stadium.common.utils.SqlMapper;
import com.stadium.common.utils.UserUtils;
import com.stadium.dto.RecordDictDto;
import com.stadium.entity.RecordDict;
import com.stadium.mapper.RecordDictMP;
import com.stadium.service.RecordDictSV;
import com.stadium.vo.RecordDictVo;
import com.stadium.vo.searchVo.RecordDictSearchVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RecordDictSVI implements RecordDictSV {
    @Autowired
    private RecordDictMP mapper;
    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<RecordDict> queryBySQL(String sql, Map<String, Object> map) {
        return sqlMapper.selectList(sql, map, RecordDict.class);
    }

    @Override
    public void save(RecordDictVo recordDictVo) {
        RecordDict recordDict = new RecordDict();
        BeanUtils.copyProperties(recordDictVo, recordDict);
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        recordDict.setCreateUser(UserUtils.getUserId());
        recordDict.setUpdateUser(UserUtils.getUserId());
        recordDict.setId(id);
        mapper.save(recordDict);
    }

    @Override
    public void update(RecordDictVo recordDictVo) {
        RecordDict recordDict = new RecordDict();
        BeanUtils.copyProperties(recordDictVo, recordDict);
        recordDict.setUpdateUser(UserUtils.getUserId());
        mapper.update(recordDict);
    }

    @Override
    public void saveBatch(List<RecordDict> list) {
        mapper.saveBatch(list);
    }

    @Override
    public void delete(String id) {
        mapper.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        mapper.deleteBatch(ids);
    }

    @Override
    public List<RecordDictDto> query(RecordDictSearchVo searchVo) {
        return mapper.query(searchVo);
    }

    @Override
    public RecordDictDto get(String id) {
        return mapper.get(id);
    }

    @Override
    public int getCount(RecordDictSearchVo searchVo) {
        return mapper.getCount(searchVo);
    }

}
